package com.gxa.controller;

import com.gxa.mapper.AddOrderDataMapper;
import com.gxa.pojo.AddOrderData;
import com.gxa.service.XsDdService;
import com.gxa.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: TOOD
 * @ClassName: ShopDtController
 * @Author: ${陈柯宇}
 * Date: 2020/9/28 16:17
 * @Version: 1.0
 */

@Controller
@RequestMapping("/spDt")
@Api(value = "执行商品销售详细操作的控制器",tags = "销售商品接口的Api")
@CrossOrigin
public class ShopDtController {

    @Resource
    AddOrderDataMapper addOrderDataMapper;

    @Resource
    XsDdService xsDdService;

    @ResponseBody
    @RequestMapping(value = "/selectByShopLike",method = RequestMethod.POST)
    @ApiOperation(value = "查询商品销售动态列表分页接口", notes = "获取时间查询分页列表", httpMethod = "post", response = String.class)
    public Map<String,Object> selectByShopLike(@RequestBody Map<String,Object> map){
        JsonResult jsonResult=new JsonResult();
        if (map.get("startDate")!=null && !map.get("startDate").equals("") &&map.get("endDate")!=null && !map.get("endDate").equals("")) {
            try {
                String number= map.get("number").toString();
                String size= map.get("size").toString();
                Integer offset =(Integer.parseInt(number)-1)*Integer.parseInt(size);
                Integer limit=Integer.parseInt(size);
                map.put("offset",offset);
                map.put("limit",limit);
                List<Map<String, Object>> shopLike = addOrderDataMapper.selectByShopDtLike(map);
                Integer count = addOrderDataMapper.selectByShopDtLikeCount();
                jsonResult.put("count",count);
                jsonResult.setCode("200");
                jsonResult.setMsg("检索成功");
                jsonResult.setData(shopLike);
            }catch (Exception e){
                e.printStackTrace();
                jsonResult.setCode("406");
                jsonResult.setMsg("系统开小差了");
            }
        }else {
            try {
                String number= map.get("number").toString();
                String size= map.get("size").toString();
                Integer offset =(Integer.parseInt(number)-1)*Integer.parseInt(size);
                Integer limit=Integer.parseInt(size);
                List<Map<String, Object>> mapList = addOrderDataMapper.selectAllByShopPage(offset,limit);
                Integer count = addOrderDataMapper.selectByShopDtLikeCount();
                jsonResult.put("count",count);
                jsonResult.setCode("200");
                jsonResult.setMsg("检索成功");
                jsonResult.setData(mapList);
            }catch (Exception e){
                e.printStackTrace();
                jsonResult.setCode("406");
                jsonResult.setMsg("系统开小差了");
            }
        }

        return jsonResult.getValues();
    }

}
